package com.cms.recursoshumanos.json.object;

import com.cms.recursoshumanos.constant.Constant;
import com.cms.recursoshumanos.json.me.JSONArray;
import com.cms.recursoshumanos.json.me.JSONException;
import com.cms.recursoshumanos.json.me.JSONObject;

public class JsonObjectAuthenticateUser 
{

	public static JsonObjectAuthenticateUser _instance = null;
	public static JsonObjectAuthenticateUser getInstance() 
	{
		if(_instance == null)
			_instance = new JsonObjectAuthenticateUser();
		
		return _instance;
	}
	public String Result;
	private JSONObject jsonObject;
	private static final String 
		AUTHENTICATEUSER = "AUTHUSER",
		AUTHENTICATEUSER_STATUS = "STATUS",
		AUTHENTICATEUSER_DATA = "DATA";

	public void fromJSON (String jsonString) 
	{
		
		if (jsonString != null)
		{
			if (!jsonString.equals(""))
			{
				try
				{
					jsonObject = new JSONObject(jsonString);	
					JSONObject authuser = jsonObject.getJSONArray(AUTHENTICATEUSER).getJSONObject(0);
					String status = authuser.getString(AUTHENTICATEUSER_STATUS);
					JSONArray data = authuser.getJSONArray(AUTHENTICATEUSER_DATA);
					
					Result = status;
					
		
				} 
				catch (JSONException ex) 
				{
					ex.printStackTrace();
					JSONObject authuser;
					try 
					{
						authuser = jsonObject.getJSONObject(AUTHENTICATEUSER);
						String status = authuser.getString(AUTHENTICATEUSER_STATUS);
						Result = status;
					} 
					catch (JSONException e) 
					{
						Result = Constant.CODE_ACCESS_DENIED;
					}
					
				}
				catch (Exception ex) 
				{
					ex.printStackTrace();
					Result = Constant.CODE_EMPTY;
				}
			}
			else
			{
				Result = Constant.CODE_NOT_SERVER_RESPONSE;
			}
		}
		else
		{
			Result = Constant.CODE_NOT_SERVER_RESPONSE;
		}
	}
	public String getResult()
	{
		return this.Result;
	}
}